﻿define(function (require) {
    var utility = require('utility/utility.js');
    var service = require('utility/service');

    return Backbone.View.extend({
        tagName: "div",
        template: _.template($("#login-container").html()),
        events: {
            "click #btn-signin'": "signIn"
        },
        initialize: function () {
            return this;
        },
        render: function () {
            $(this.el).html(this.template({}));
            console.log("login container render");

            $('#login-page').append(this.el);

            return this;
        },
        signIn: function () {
            var userName = $('#name').val();
            var password = $('#password').val();

            service.Login(function (e) {
                service.setAuthToken(e.Data.Token);
                if (e.Status == "Success") {
                    EventProxy.trigger(EventProxy.Events.loginSuccess, e);
                }
            }, { userName: userName, password: password })

        },
        clear: function () {
            $(this.el).remove();
        }
    });

});